using System;
using UnityEngine;

public class HoleTrigger : MonoBehaviour
{
	[Serializable]
	public class EditorReferences
	{
		public string targetTag = "FallingObject";

		public string layerOnEnter = "InHole1";

		public string layerOnExit = "OnGround";
	}

	[SerializeField]
	public EditorReferences references = new EditorReferences();

	private int _layerOnEnter;

	private int _layerOnExit;

	private int _currentSize;

	private void Awake()
	{
		_layerOnEnter = LayerMask.NameToLayer(references.layerOnEnter);
		_layerOnExit = LayerMask.NameToLayer(references.layerOnExit);
	}

	public void SetMinimumSize(int size)
	{
		_currentSize = size;
	}

	public void SetLayerOnEnter(string layerName)
	{
		_layerOnEnter = LayerMask.NameToLayer(layerName);
	}

	private void OnTriggerEnter(Collider other)
	{
		if (other.gameObject.CompareTag(references.targetTag) && other.gameObject.layer == _layerOnExit)
		{
			FallingObject componentInParent = other.GetComponentInParent<FallingObject>();
			if ((bool)componentInParent && componentInParent.SizeRequired <= _currentSize)
			{
				componentInParent.RaiseFallingStateChanged(state: true);
				other.gameObject.layer = _layerOnEnter;
			}
		}
	}

	private void OnTriggerStay(Collider other)
	{
		if (other.gameObject.CompareTag(references.targetTag) && other.gameObject.layer == _layerOnExit)
		{
			FallingObject componentInParent = other.GetComponentInParent<FallingObject>();
			if ((bool)componentInParent && componentInParent.SizeRequired <= _currentSize)
			{
				componentInParent.RaiseFallingStateChanged(state: true);
				other.gameObject.layer = _layerOnEnter;
			}
		}
	}

	private void OnTriggerExit(Collider other)
	{
		if (other.gameObject.CompareTag(references.targetTag))
		{
			FallingObject componentInParent = other.GetComponentInParent<FallingObject>();
			if ((bool)componentInParent)
			{
				componentInParent.RaiseFallingStateChanged(state: false);
			}
			other.gameObject.layer = _layerOnExit;
		}
	}
}
